package com.ykg.service.impl;

import com.ykg.dto.EntrustDTO;
import com.ykg.mapper.EntrustMapper;
import com.ykg.mapper.ListMapper;
import com.ykg.pojo.Entrust;
import com.ykg.service.ICleanShipService;
import com.ykg.service.IDTOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 类(接口)：
 * Created on 2021/6/25 16:04.
 * Author: zetong
 * Description:
 */
@Service
public class CleanShipServiceImpl implements ICleanShipService {

    @Autowired
    private EntrustMapper entrustMapper;
    @Autowired
    private IDTOService idtoService;
    @Autowired
    private ListMapper listMapper;


    @Override//装卸部获得待清仓委托单的列表
    public List<Entrust> getEntrustLoadAndUnload(){
        List<Entrust> entrusts = new ArrayList<Entrust>();
        entrusts.addAll(entrustMapper.getEntrustByEndState(1));
        entrusts.addAll(entrustMapper.getEntrustByEndState(3));
        entrusts.addAll(entrustMapper.getEntrustByEndState(4));
        return entrusts;
    }
    @Override//流动机械部获得待清仓委托单的列表
    public List<Entrust> getEntrustMachine(){
        List<Entrust> entrusts = new ArrayList<Entrust>();
        entrusts.addAll(entrustMapper.getEntrustByEndState(1));
        entrusts.addAll(entrustMapper.getEntrustByEndState(2));
        entrusts.addAll(entrustMapper.getEntrustByEndState(4));
        return entrusts;
    }

    @Override//获得委托单细节
    public EntrustDTO getEntrustDetailed(String entrustId){
        Entrust entrust = entrustMapper.findByEntrustId(entrustId);
        EntrustDTO entrustDTO = idtoService.createEntrustDTO(entrust);
        return entrustDTO;
    }
    @Override//装卸部完成
    public int finishEntrustLoadAndUnload(String entrustId){
        Entrust entrust = entrustMapper.findByEntrustId(entrustId);
        int result = 0;
        int endState = entrust.getEndState()+1;
        result = entrustMapper.updateEndState(entrustId,endState);
        if(endState == 4){
            listMapper.updateFdate(entrust.getListId(),new Date());
        }
        return result;
    }
    @Override//流动机械部完成
    public int finishEntrustMachine(String entrustId){
        Entrust entrust = entrustMapper.findByEntrustId(entrustId);
        int result = 0;
        int endState = entrust.getEndState()+2;
        result = entrustMapper.updateEndState(entrustId,endState);
        if(endState == 4){
            listMapper.updateFdate(entrust.getListId(),new Date());
        }
        return result;
    }
}
